package com.tocean.app.dto.request;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * 功能描述：
 *
 * @Author 梁展鹏
 * @Date 2020/5/14 23:58
 */
@ApiModel(value = "BasePageRequest", description = "分页请求协议")
@JsonIgnoreProperties(ignoreUnknown = true)
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class BasePageRequest<T> extends BaseRequest<T> {

    @ApiModelProperty(value = "开始页", notes = "默认第1页", example = "1", required = true, hidden = false)
    @Min(1)
    @NotNull(message = "start:不能为空")
    private Integer start = 1;

    @ApiModelProperty(value = "每页数据", notes = "默认一页10条", example = "10", required = true, hidden = false)
    @Min(1)
    @NotNull(message = "limit:不能为空")
    private Integer limit = 10;

    /**
     * 功能描述：前端是从第1页开始算起。后端的分页查询是第0页算期。
     *
     * @return
     */
    @JsonIgnore
    public Integer getPage() {
        return start >= 1 ? start - 1 : start;
    }

}
